package com.allen.excelUtils.format;

import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.Cell;


public abstract class RFormatter {

	protected Object getValue(Cell cell) {
		if (cell == null) {
			return StringUtils.EMPTY;
		}
		Object obj = null;
		switch (cell.getCellType()) {
		case HSSFCell.CELL_TYPE_BLANK:
			obj = StringUtils.EMPTY;
			break;
		case HSSFCell.CELL_TYPE_BOOLEAN:
			obj = cell.getBooleanCellValue();
			break;
		case HSSFCell.CELL_TYPE_NUMERIC:
			if (HSSFDateUtil.isCellDateFormatted(cell)) {
				obj = cell.getDateCellValue();
			}else {
				obj = cell.getNumericCellValue();	
			}
				
			break;
		case HSSFCell.CELL_TYPE_STRING:
			obj = cell.getStringCellValue();
			break;
		default:
			obj = cell.getStringCellValue();
			break;
		}

		return obj;
	}
}
